<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function findall(a, x) {
            var result = [];
            var len = a.length;
            var pos = 0;
            while (pos < len) {
                pos = a.indexOf(x, pos);
                if (pos === -1) {
                    break;
                }
                result.push(pos);
                pos++;
            }
            return result;
        }
        var arr = ['a', 'b', 'd', 'd', 'c', 'd', 'd'];
        document.write(findall(arr, 'd') + '</br>')

        function count(arr, x) {
            var number = 0;
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == x) {
                    number++;
                }
            }
            return number;
        }
        document.write(count(arr, 'd'))
    </script>
</body>

</html>